<?php 
namespace app\common\model;
class Accessory extends Common{
	protected $insert = ['addtime'=>SYS_TIME];
	protected function getAddtimeAttr($value){
		return date('Y-m-d H:i:s', $value);
	}
	//添加数据
	public function save_data($data){ 
		//allowField过滤post数组中的非数据表字段数据
		$result = $this->allowField(true)->isUpdate(false)->data($data)->save();
		if($result!==false){
			$pk = $this->getPk();
			$id = $this->$pk;
			return $id;
		}
		return false;
	}
	public function get_fileurl($value){
		if (!$value) return [];
		$list = $this->list_data(['id'=>['in', $value]]);
		$info = [];
		foreach ($list as $v) {
			if(strpos($v['fileurl'],"http://") !== false){
				$info[] = $v['fileurl'];
			}else{
				$info[] = $v['fileurl'] ? rtrim(APP_URL,"/").$v['fileurl'] : '';
			}
		}
		return $info;
	}
	public function list_datas($contentid, $typeid){
		$list = $this->where('contentid', $contentid)->where('typeid', $typeid)->order('id asc')->select();
		$lists = [];
		foreach ($list as $v) {
			if(strpos($v['fileurl'],"http://") !== false){
				$info['thumb'] = $v['fileurl'];
			}else{
				$info['thumb'] = $v['fileurl'] ? rtrim(APP_URL,"/").$v['fileurl'] : '';
			}
			$info['thumbnail'] = $v['fileurl'] ? rtrim(APP_URL,"/").thumb($v['fileurl'], 300, 300, 0) : '';
			$lists[] = $info;
		}
		return $lists;
	}
}